<?
header('Content-type: application/rss+xml');
include_once("includes/common_public_inc.php");
$tplRss=new TplLoad;
$tplRss->caching = true;

if (!$tplRss->is_cached("rss_feed.tpl",getParam("cat","")))
{
	addToHistory(17,"","","");
	if ($set_rss_generate)
	{
		$lCat=getParamInt("cat","");
		$lType=getParam("type","");
		
		if ($lType=="best_rated")
		{
			$lCat="";
			$lOrder=" order by ad_totalscore desc";	
		}
		else if ($lType=="most_viewed")
		{
			$lCat="";
			$lOrder=" order by ad_views desc";	
		}
		else if ($lCat)
		{
			$lCat=" AND $cat_tbl.cat_id =$lCat";
			$lOrder=" order by ad_date desc, ad_id desc";
		}
		else 
		{
			$lCat="";
			$lOrder=" order by ad_date desc, ad_id desc";
		}

		
		
		$tplRss->assign("lastbuild",date("D, j M Y H:i:s",time()));
		$tplRss->assign("language",$set_language);
		$tplRss->assign("url",$set_url);
		$tplRss->assign("sitename",$set_sitename);
		
		$lCatName="";
		if ($set_multilang_cat)
			$lColCat = "lang_" . $set_language;
		if (!$lCatName)
			$lColCat = "cat_name";
		
		/*JMR: Validacion de avisos pagos*/
		$val_string= " AND ad_is_validated = 1";
		if ($set_validation==1) // If ad validation is on, only show ad_is_valid=1 ads
			$val_string .= " AND ad_is_validated = 1";			
		
			
		$sql_links = "select ad_id,ad_title,ad_description,ad_date,$lColCat as cat_name,$cat_tbl.cat_id from $ads_tbl inner join $cat_tbl on $ads_tbl.ad_cat_id = $cat_tbl.cat_id  $val_string $lCat $lOrder limit $set_rss_limit"; 
	
		$result = q($sql_links); 
		
		$i=0;
		
		while($row=mysql_fetch_array($result))
		{ 
			$lPub="EST";
			$sitetitle = ""; 
			$ad_id = $row["ad_id"]; 
			$ad_title=$row["ad_title"];
			$ad_description=$row["ad_description"];
			$datestamp = date("D, j M Y H:i:s",$row["ad_date"]);
			$catname = $row["cat_name"]; 
			$link="http://$set_url/" . linkDetail($ad_id);	
			
			$lArray[$i]["title"]=$ad_title;
			$lArray[$i]["descr"]=$ad_description;
			$lArray[$i]["date"]=$datestamp;
			$lArray[$i]["catname"]=$catname;
			$lArray[$i]["link"]=$link;
			$i++;
		}
		
	
		$tplRss->assign("rss_list",$lArray);
	}
}

$tplRss->caching = 2; 
$tplRss->cache_lifetime = 3600;
$tplRss->display("rss_feed.tpl",getParamInt("cat",""));?>